<?php 
  require_once("includes/config.php"); 
  
  $sql = 'SELECT * FROM apartments
  where owner_id = ? and (status = 2 or status = 3)';

  $binds = array();
  
  $binds['owner_id'] = $_SESSION['user_id'];

 /* if(isset($_GET['apart_id']) && $_GET['apart_id'] != -1) 
  {
    if(!empty($binds))
      $and = " and ";
    else
      $and = " ";
           
    $binds['id'] = $_GET['apart_id'];
    $sql .= $and."apartments.id  = ?";
    $sqlCount .= $and."apartments.id  = ?";
  } */
                
    
  //dump($sql);
  $aprts = query($sql,$binds);
  $currentdate = date('m/d/Y', time());
  $dates = query('SELECT * FROM periods');
  $i = 1;
  foreach($dates as $date)
  {
    if(check_in_range($date['period_from'], $date['period_to'], $currentdate))
    {
      $period = $i;
      break;
    }
    $i++;
  }
  if(!isset($period))
    $period = 1;
 
  require("Contract_pops/choose_apartment.php");
?>